<!--
 * @Author: DeluxePig
 * @LastEditors: DeluxePig 250293786@qq.com
 * @Date: 2024-06-24 23:18:30
 * @LastEditTime: 2024-06-27 22:58:39
 * @Description: 人工对话
-->
<template>
  <div class="manual-session-box">
    <div class="manual-title">人工对话</div>
    <div class="end-btn" @click="closeFun()">
      <i class="iconfont icon-tubiaozhizuomobanyihuifu-"></i><span class="iconfont"></span>结束对话
    </div>
    <div class="session-body">
      <!-- <div class="time-tips">{{ sessionList[0].create_datetime }}</div> -->
      <div v-for="(item, index) in sessionList" :key="index" class="news-div">
        <div class="news-box news-answer" v-if="item.type === 'query'">
          <div class="img-box">
            <img :src="userData.icon ? userData.icon : userIcon" alt="" />
          </div>
          <div class="info-box">
            <div class="text">{{ item.text }}</div>
          </div>
        </div>
        <div class="news-box news-query" v-else>
          <div class="img-box">
            <img :src="userIcon" alt="" />
          </div>
          <div class="info-box">
            <div class="text">{{ item.data.nlp_content }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="int-box">
      <div class="int-area">
        <textarea class="z-text" placeholder="请输入问题" v-model="question" @keyup.enter="sendFun()"></textarea>
      </div>
      <div class="send-btn" @click="sendFun()">发送</div>
    </div>
  </div>
</template>

<script>
import { getInfo } from '@/api/user'
import userIcon from '@/assets/images/user-logo.png'
import { sendquestionApi } from '@/api/knowledge'
// import { createBanner } from '@/api/banner'
export default {
  props: {
    modelUniqueid: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      userData: {},
      userIcon: userIcon,
      question: '',
      sessionList: []
    }
  },
  watch: {
    // modelUniqueid: {
    //   handler(nv, oldName) {
    //     if (nv) {
    //       console.log(nv)
    //     }
    //   },
    //   immediate: true,
    //   deep: true
    // }
  },
  created() {
    this.gertUserData()
  },
  methods: {
    gertUserData() {
      getInfo().then((res) => {
        this.userData = res.data
        localStorage.setItem('userData', JSON.stringify(res.data))
      })
    },
    sendFun() {
      this.sessionList.push({
        type: 'query',
        text: this.question
      })
      const data = {
        query: this.question,
        model_uniqueid: this.modelUniqueid
      }
      this.question = ''
      sendquestionApi(data).then((res) => {
        this.sessionList.push({
          type: 'answer',
          data: res.data
        })
      })
    },
    closeFun() {
      this.$emit('close')
    }
  }
}
</script>
<style lang="scss" scoped>
.manual-session-box {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 20px;

  .manual-title {
    font-weight: 600;
    font-size: 20px;
    color: #1C1F23;
    line-height: 23px;
    text-align: left;

  }

  .end-btn {
    width: 112px;
    height: 30px;
    line-height: 30px;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid #E0E0E0;
    text-align: center;
    margin: 10px 0;
    font-weight: 400;
    font-size: 14px;
    color: #FF3F40;
    cursor: pointer;

    .iconfont {
      margin-right: 3px;
    }
  }

  .int-box {
    width: 100%;
    height: 80px;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;

    .int-area {
      width: calc(100% - 88px);
      height: auto;
      background: #F4F5F9;
      border-radius: 4px;

      .z-text {
        width: 100%;
        min-height: 36px;
        max-height: 72px;
        outline: 0;
        background: none;
        padding: 3px;
        resize: block;
        font-size: 14px;
      }
    }

    .send-btn {
      cursor: pointer;
      width: 68px;
      height: 36px;
      line-height: 36px;
      text-align: center;
      font-size: 14px;
      color: #FFFFFF;
      background: linear-gradient(90deg, #39D9C6 0%, #39CFA2 100%);
    }
  }

  .session-body {
    width: 100%;
    height: calc(100% - 145px);
    overflow-y: auto;
    border-top: 1px solid #E0E0E0;

    .time-tips {
      width: 100%;
      font-weight: 400;
      font-size: 12px;
      color: #9E9E9E;
      line-height: 36px;
      text-align: center;
    }

    .news-div {
      width: 100%;
    }

    .news-box {
      width: 100%;
      height: auto;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      cursor: pointer;
      position: relative;
      margin: 45px 0;

      .img-box {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: #eee;
        overflow: hidden;
        position: relative;
        z-index: 1;
        margin: 0 12px;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .info-box {
        padding-left: 14px;
        width: auto;
        max-width: calc(100% - 65px);
        position: relative;
        padding: 12px;
        background: #F4F5F9;
        border-radius: 0px 12px 12px 12px;

        .text {
          font-size: 14px;
          color: #6A6B6C;
          line-height: 20px;
          text-align: left;
        }
      }
    }

    .news-answer {
      justify-content: end;
      padding-left: 30%;
      padding-right: 0;
      align-items: center;
      flex-direction: row-reverse;
      position: relative;

      .info-box {
        background: linear-gradient(90deg, #DFF9EE 0%, #C7F6E6 100%);
        border-radius: 12px 0px 12px 12px;
        position: relative;

        .add-btn {
          position: absolute;
          right: 0;
          bottom: -25px;
          border-radius: 4px 4px 4px 4px;
          border: 1px solid #04D1B8;
          width: 94px;
          height: 22px;
          font-size: 12px;
          color: #04D1B8;
          line-height: 22px;
          text-align: center;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
